package com.aind.category.controller;

import com.aind.category.model.Category;
import com.aind.category.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lpeng on 2017/2/23.
 */
@Controller
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ResponseBody
    @RequestMapping("/getCategoryMenu")
    public List<Map<Object, Object>> getCategoryMenu(){
        List<Map<Object, Object>> mapList = new ArrayList<Map<Object, Object>>();
        List<Category> categoryList = categoryService.getAllForCategoryMenu();
        for (Category category : categoryList) {
            Map<Object, Object> map = new HashMap<Object, Object>();
            map.put("categoryId", category.getCategoryId());
            map.put("pName", category.getpName());
            map.put("name", category.getName());
            mapList.add(map);
        }
        return mapList;
    }
}
